﻿using System;
using System.Collections.Generic;
using System.Text;
using UnionnetClient.Model;
using System.Windows.Forms;

namespace UnionnetClient
{
	class UnloginStateWithUI : UnloginState
	{
		public UnloginStateWithUI(StateMachine stateMachine)
			: base(stateMachine)
		{
			base.ProcessException = _ProcessException;
		}

		public void SetMainForm(MainForm mainForm)
		{
			this.mainForm = mainForm;
		}

		public override void Login()
		{
			mainForm.ToolStripLogin.Text = "取消登陆";
			base.Login();
		}

		public override void Exit()
		{
			base.Exit();
			Application.Exit();
		}

		protected override void OnLoginTimeout()
		{
			base.OnLoginTimeout();
			mainForm.ToolStripLogin.Text = "登陆";//登陆终止②
			mainForm.NotifyIcon.ShowBalloonTip(10000, "登陆超时", "请稍候再试", ToolTipIcon.Error);
		}

		protected override void OnLoginCompleted()
		{
			base.OnLoginCompleted();
			mainForm.ToolStripLogin.Text = "登陆";//登陆终止③
		}

		private void _ProcessException(Exception ex)
		{
			mainForm.ToolStripLogin.Text = "登陆"; //登陆终止①
			if (ex.Message.Contains("重复"))
			{
				mainForm.NotifyIcon.ShowBalloonTip(5000, "之前已经登入", "不能识别登陆模式", ToolTipIcon.Info);
			}
			else
			{
				MessageBox.Show(ex.Message, "错误 - 聚友登陆客户端", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
			}
		}

		private MainForm mainForm;
	}
}
